package com.tvein.system.view
{
	//flash
	//pureMVC
	import org.puremvc.as3.multicore.patterns.mediator.Mediator;
	import org.puremvc.as3.multicore.interfaces.IMediator;
	import org.puremvc.as3.multicore.interfaces.INotification;
	//custom
	import com.tvein.system.common.CommonConstants;
	import com.tvein.System;
	import com.tvein.system.controller.FileLoader.FileDownload;
	import com.tvein.system.controller.FileLoader.SendFileNeed;
//
    public class FileLoaderMediator extends Mediator implements IMediator
    {
        public static const NAME:String = 'FileLoaderMediator';
     
		public function FileLoaderMediator()
		{
			super(NAME);
		}
		
		//Custom
		override public function onRegister() : void
        {
			//FileLoader Command
			/*  -D download  */
			facade.registerCommand(CommonConstants.FILELOADER_DOWNLOAD, FileDownload);
			/*  -N needfile  */
			facade.registerCommand(CommonConstants.FILELOADER_FILENEED, SendFileNeed);
        }
		
		override public function listNotificationInterests() : Array
		{
			var interests:Array = super.listNotificationInterests();
			interests.push(CommonConstants.FILELOADER);
			return interests;
		}
		
		override public function handleNotification(notification:INotification) : void
		{
			switch(notification.getName())
			{
				case CommonConstants.FILELOADER:
					var params:Array = notification.getBody()[0].split(" ");
					
					trace(notification.getBody()[1]);
					
					switch(params[1])
					{
						case "-D":
							sendNotification(CommonConstants.FILELOADER_DOWNLOAD, notification.getBody()[1]);
							break;
						case "-N":
							sendNotification(CommonConstants.FILELOADER_FILENEED, notification.getBody()[1]);
							break;
					}
					break;
			}
		}
    }
}